home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 10
/
AACD 10.iso
/
AACD
/
Magazine
/
Online
/
httpproxy
/
changeinstall.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1996-08-20
|
2KB
|
74 lines
/* Change one line in a configuration file, add it when it is not already there. */
/* Usage: rx changeinstall.rexx File/A //-Text-//Str1 Str2 Str3 */
/*
* A copy of every 'file' is made into 'file.rexxbackup'.
*
* The first line that contains all Strs will be replaced by Text.
* When no line is found that contains all Strs, the line is added to the end of the file.
*
* When a write fails or the ending statement is missing, the backup file
* is restored and the script returns 20.
*/
parse arg File pad "---" Text "---" rest
parse var rest Str1 Str2 Str3
address command
if ~exists(File) then
exit 20
if Str1 == "" then
exit 20
if Str2 == "" then
Str2 = Str1
if Str3 == "" then
Str3 = Str2
"delete >nil: "File".rexxbackup"
"rename "File File".rexxbackup"
if (open("r",File".rexxbackup","READ") ~= 1) then
do
say "Reading file "File" failed..."
"rename "File".rexxbackup "File /* and rename back... */
exit 20
end
if (open("w",File,"WRITE") ~= 1) then
do
say "Writing to file "File" failed..."
"rename "File".rexxbackup "File /* and rename back... */
exit 20
end
if (open("f","env:_httpproxy_files","APPEND") ~= 1) then
exit 20
call writeln("f",File": "Text)
call close("f")
added = 0
do while (eof("r") = 0)
line = readln("r")
if (line == "" & eof("r") = 1) then
leave
if (InExp(line)) then
do
added = 1
call writeln("w",Text)
end
else
call writeln("w",line)
end
if ((~ added) & (Text ~== "")) then
call writeln("w",Text)
call close("r")
call close("w")
exit 0
InExp: procedure expose Str1 Str2 Str3
parse Arg n
if (index(n,Str1) ~= 0 & index(n,Str2) ~= 0 & index(n,Str3) ~= 0) then
return 1
return 0